include('shared.lua')

function ShowSwitchTeamMenu() 	
	local frame = vgui.Create("DFrame")
	frame:SetPos(ScrW() / 2 - 100, ScrH() / 2 - 80) --Set the window in the middle of the players screen/game window
	frame:SetSize(200, 185) --Set the size
	frame:SetTitle("Team Selection") --Set title
	frame:SetVisible(true)
	frame:SetDraggable(false)
	frame:ShowCloseButton(true)
	frame:MakePopup()
	
	local buttonWidth = 196
	local blueTeamButton = vgui.Create("DButton", frame)
	blueTeamButton:SetPos(2, 25) --Place it half way on the tall and 5 units in horizontal
	blueTeamButton:SetSize(buttonWidth, 50)
	blueTeamButton:SetText("Blue")
	blueTeamButton.DoClick = 
		function()
			RunConsoleCommand("sj_join_team", tostring(DsTeam.Blue))
			frame:Remove()
		end
	 
	local redTeamButton = vgui.Create("DButton", frame)
	redTeamButton:SetPos(2, 75) --Place it next to our previous one
	redTeamButton:SetSize(buttonWidth, 50)
	redTeamButton:SetText("Red")
	redTeamButton.DoClick = 
		function()
			RunConsoleCommand("sj_join_team", tostring(DsTeam.Red))
			frame:Remove()
		end
		
	local spectatorTeamButton = vgui.Create("DButton", frame)
	spectatorTeamButton:SetPos(2, 125)  --Place it next to our previous one
	spectatorTeamButton:SetSize(buttonWidth, 50)
	spectatorTeamButton:SetText("Spectator")
	spectatorTeamButton.DoClick = 
		function()
			RunConsoleCommand("sj_join_team", "spec")
			frame:Remove()
		end
end

isMKeyDown = false
hook.Add("Think", "KeyBoard", function()
		if input.IsKeyDown(KEY_M) and !isMKeyDown then
			RunConsoleCommand("sj_team_menu")
			isMKeyDown = true
		elseif !input.IsKeyDown(KEY_M) and isMKeyDown then
			isMKeyDown = false
		end
	end)

concommand.Add("sj_team_menu", ShowSwitchTeamMenu)